﻿package mortal.game.view.guild.otherpanel
{
    import Message.Game.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.guild.cellrender.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildWarnMembersPanel extends GuildOtherBasePanel
    {
        private var _list:GTileList;
        private var _btnExpel:GButton;
        private var _pageSelecter:PageSelecter;
        private var _rightSp:Sprite;
        private var _comboDays:GComboBox;
        private var _comboChatTimes:GComboBox;
        private var _comboContribution:GComboBox;
        private var _btnSave:GButton;
        private static var _instance:GuildWarnMembersPanel;

        public function GuildWarnMembersPanel(param1:ILayer = null)
        {
            super(param1);
            setSize(610, 385);
            this.title = "" + Language.getString(71255);
            return;
        }// end function

        override public function layoutUI() : void
        {
            super.layoutUI();
            pushUIToDisposeVec(UIFactory.bg(10, 40, 445, 320, this));
            pushUIToDisposeVec(UIFactory.bg(10, 40, 445, 24, this, ImagesConst.RegionTitleBg));
            UIFactory.gTextField(Language.getString(60026), 53, 42, 54, 20, this);
            UIFactory.gTextField(Language.getString(60034), 140, 42, 30, 20, this);
            UIFactory.gTextField(Language.getString(60029), 200, 42, 65, 20, this);
            UIFactory.gTextField(Language.getString(60038), 285, 42, 40, 20, this);
            UIFactory.gTextField(Language.getString(60088), 355, 42, 100, 20, this);
            this._list = UIFactory.tileList(10, 62, 440, 290, this);
            this._list.rowHeight = 29;
            this._list.columnWidth = 440;
            this._list.setStyle("cellRenderer", GuildWarnMemberListCellRenderer);
            this._pageSelecter = UIFactory.pageSelecter(170, 360, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, GlobalStyle.textFormatBai.center());
            this._pageSelecter.maxPage = 1;
            this._pageSelecter.currentPage = 1;
            this._pageSelecter.pageTextBoxSize = 40;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._btnExpel = UIFactory.gButton("" + Language.getString(71256), 385, 360, 65, 22, this);
            this._rightSp = UIFactory.sprite(460, 40, this);
            pushUIToDisposeVec(UIFactory.bg(0, 0, 150, 320, this._rightSp));
            var _loc_1:* = GlobalStyle.textFormatHuang2.center();
            _loc_1.size = 14;
            pushUIToDisposeVec(UIFactory.textField("" + Language.getString(71257), 0, 2, 150, 24, this._rightSp, _loc_1));
            pushUIToDisposeVec(UIFactory.textField("" + Language.getString(71258), 5, 10 + 22, 120, 22, this._rightSp, GlobalStyle.textFormatLv));
            pushUIToDisposeVec(UIFactory.textField("" + Language.getString(71259), 5, 60 + 22, 120, 22, this._rightSp, GlobalStyle.textFormatLv));
            pushUIToDisposeVec(UIFactory.textField("" + Language.getString(71260), 5, 110 + 22, 120, 22, this._rightSp, GlobalStyle.textFormatLv));
            this._comboDays = UIFactory.gComboBox(5, 30 + 22, 140, 22, null, this._rightSp);
            this._comboChatTimes = UIFactory.gComboBox(5, 80 + 22, 140, 22, null, this._rightSp);
            this._comboContribution = UIFactory.gComboBox(5, 130 + 22, 140, 22, null, this._rightSp);
            this._btnSave = UIFactory.gButton("" + Language.getString(71261), 42, 195, 65, 22, this._rightSp);
            this.initComboxsData();
            Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_warnMemberList_get));
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateList();
            return;
        }// end function

        override public function update() : void
        {
            super.update();
            this.setComboxsData();
            this.updateList();
            return;
        }// end function

        public function updateList() : void
        {
            var _loc_1:Array = null;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            if (Cache.instance.guild.selfGuildInfo)
            {
                _loc_1 = Cache.instance.guild.selfGuildInfo.warnMemberList.concat();
                _loc_2 = 10;
                this._pageSelecter.maxPage = Math.ceil(_loc_1.length / _loc_2);
                _loc_3 = (this._pageSelecter.currentPage - 1) * _loc_2;
                _loc_4 = Math.min(_loc_3 + _loc_2, _loc_1.length);
                _loc_1.splice(_loc_4);
                _loc_1.splice(0, (_loc_3 - 1));
                this._list.dataProvider = new DataProvider(_loc_1);
                this._list.drawNow();
            }
            return;
        }// end function

        override public function onMouseClick(event:MouseEvent) : void
        {
            var _loc_2:Object = null;
            var _loc_3:SWarningMember = null;
            super.onMouseClick(event);
            switch(event.target)
            {
                case this._btnSave:
                {
                    _loc_2 = {};
                    _loc_2.days = this._comboDays.selectedItem.value;
                    _loc_2.activity = 0;
                    _loc_2.chatTimes = this._comboChatTimes.selectedItem.value;
                    _loc_2.contributionWeek = this._comboContribution.selectedItem.value;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_warnCondition_set, _loc_2));
                    break;
                }
                case this._btnExpel:
                {
                    if (this._list.selectedIndex == -1)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71262));
                        return;
                    }
                    _loc_3 = this._list.dataProvider.getItemAt(this._list.selectedIndex) as SWarningMember;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_KICK_OUT_MEMEBER, _loc_3.miniPlayer.entityId.id));
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._list.dispose(param1);
            this._btnExpel.dispose(param1);
            this._pageSelecter.dispose(param1);
            DisplayUtil.removeMe(this._rightSp);
            this._comboDays.dispose(param1);
            this._comboChatTimes.dispose(param1);
            this._comboContribution.dispose(param1);
            this._btnSave.dispose(param1);
            this._list = null;
            this._btnExpel = null;
            this._pageSelecter = null;
            this._rightSp = null;
            this._comboDays = null;
            this._comboChatTimes = null;
            this._comboContribution = null;
            this._btnSave = null;
            return;
        }// end function

        override public function quickDispose() : void
        {
            return;
        }// end function

        override protected function setWindowCenter() : void
        {
            return;
        }// end function

        private function initComboxsData() : void
        {
            var _loc_1:* = GuildConst.WarnDayArr.concat();
            var _loc_2:* = new DataProvider();
            _loc_2.addItem({label:Language.getString(71263), index:0, value:0});
            var _loc_3:int = 1;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_2.addItem({label:Language.getStringByParam(60089, _loc_1[_loc_3]), index:_loc_3, value:_loc_1[_loc_3]});
                _loc_3++;
            }
            this._comboDays.dataProvider = _loc_2;
            this._comboDays.selectedIndex = 2;
            _loc_1 = GuildConst.WarnActiviyArr.concat();
            var _loc_4:* = new DataProvider();
            _loc_4.addItem({label:"" + Language.getString(71263), index:0, value:0});
            _loc_3 = 1;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_4.addItem({label:Language.getStringByParam(60090, _loc_1[_loc_3]), index:_loc_3, value:_loc_1[_loc_3]});
                _loc_3++;
            }
            _loc_1 = GuildConst.WarnChatArr.concat();
            var _loc_5:* = new DataProvider();
            _loc_5.addItem({label:Language.getString(71263), index:0, value:0});
            _loc_3 = 1;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_5.addItem({label:Language.getStringByParam(60091, _loc_1[_loc_3]), index:_loc_3, value:_loc_1[_loc_3]});
                _loc_3++;
            }
            this._comboChatTimes.dataProvider = _loc_5;
            this._comboChatTimes.selectedIndex = 2;
            _loc_1 = GuildConst.WarnContributionArr.concat();
            var _loc_6:* = new DataProvider();
            _loc_6.addItem({label:"" + Language.getString(71263), index:0, value:0});
            _loc_3 = 1;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_6.addItem({label:Language.getStringByParam(60092, _loc_1[_loc_3]), index:_loc_3, value:_loc_1[_loc_3]});
                _loc_3++;
            }
            this._comboContribution.dataProvider = _loc_6;
            this._comboContribution.selectedIndex = 2;
            return;
        }// end function

        public function setComboxsData() : void
        {
            var _loc_1:* = Cache.instance.guild.selfGuildInfo.warnSetting;
            this._comboChatTimes.selectedIndex = this.findDataProvideIndex(this._comboChatTimes.dataProvider, _loc_1.chatTimes);
            this._comboContribution.selectedIndex = this.findDataProvideIndex(this._comboContribution.dataProvider, _loc_1.contributionWeek);
            this._comboDays.selectedIndex = this.findDataProvideIndex(this._comboDays.dataProvider, _loc_1.days);
            return;
        }// end function

        private function findDataProvideIndex(param1:DataProvider, param2:int) : int
        {
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            while (_loc_4 < param1.length)
            {
                
                _loc_3 = param1.getItemAt(_loc_4);
                if (_loc_3.value == param2)
                {
                    return _loc_3.index;
                }
                _loc_4++;
            }
            return 0;
        }// end function

        public static function get instance() : GuildWarnMembersPanel
        {
            if (_instance == null)
            {
                _instance = new GuildWarnMembersPanel;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
